package com.canvas.base;

import com.canvas.pojo.User;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Author: 宗恣
 * @Date: 2018/9/4 0004 16:55
 */
public class LoginUserUtil {

    public static User load() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        if (null != principal && principal instanceof User) {
            return (User) principal;
        }

        return null;
    }

    public static Long getLonginUserId() {
        User user = load();
        if (null == user) {
            return null;
        }

        return user.getId();
    }

}
